/*
  spr-sdk: Statistical Pattern Recognition SDK
  Copyright (C) 2010 Marco Ambu

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _PR_TRAININGSET_H
#define	_PR_TRAININGSET_H

#include "pr/UniquePattern.h"

namespace pr {

class TrainingSet
{
public:
  static UniquePattern NullPattern;

public:
  TrainingSet(std::size_t numFeatures);

  void add(const Pattern& pattern, std::size_t classId);

  void transform(Pattern::Operation& operation);

  void clear();

  std::size_t featureCount() const;
  std::size_t patternCount() const;
  std::size_t classCount() const;

  const UniquePattern& getPatternById(std::size_t patternId);

  // To enumerate patterns
  UniquePattern& getPattern(std::size_t index);
  const UniquePattern& getPattern(std::size_t index) const;

//  Pattern& operator[](std::size_t index);
//  const Pattern& operator[](std::size_t index) const;

private:
  class IdGenerator
  {
  public:
    IdGenerator() : id_(0) {}
    std::size_t nextId() { return ++id_; }

  private:
    std::size_t id_;
  };

  class PatternSet;

private:
  typedef std::vector<PatternSet>::iterator iterator;
  typedef std::vector<PatternSet>::const_iterator const_iterator;

private:
  IdGenerator idGenerator_;
  std::vector<PatternSet> set_;
  std::size_t numFeatures_;
  std::size_t numPatterns_;
};

class TrainingSet::PatternSet
{
public:
  PatternSet(std::size_t classId);

  std::size_t classId() const { return classId_; }
  std::size_t patternCount() const { return patterns_.size(); }

  void add(const UniquePattern& pattern);

  UniquePattern& operator[](std::size_t i);
  const UniquePattern& operator[](std::size_t i) const;

private:
  typedef std::vector<UniquePattern>::iterator iterator;
  typedef std::vector<UniquePattern>::const_iterator const_iterator;

private:
  std::size_t classId_;
  std::vector<UniquePattern> patterns_;
};

} // namespace pr

#endif	// _PR_TRAININGSET_H
